package org.example.springiocdemo;

import org.example.springiocdemo.Controller.UserController;
import org.example.springiocdemo.Controller.UserController2;
import org.example.springiocdemo.Controller.UserController3;
import org.example.springiocdemo.config.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
public class SpringIoCDemoApplication {

    public static void main(String[] args) {
        //获取Spring上下文对象
        ApplicationContext context = SpringApplication.run(SpringIoCDemoApplication.class, args);
        //从Spring上下文中获取对象
//        UserController bean = context.getBean(UserController.class);
//        bean.hello();
//
//        //获取Bean对象的方式
//        UserController userController = (UserController) context.getBean("userController");
//        userController.hello();
//        UserController userController1 =context.getBean("userController",UserController.class);
//        userController1.hello();
//        System.out.println(userController);
//        System.out.println(userController1);
//        UserService bean = context.getBean(UserService.class);
//        bean.hello();
//        UserReposity bean = context.getBean(UserReposity.class);
//        bean.hello();
//        UserComponent bean = context.getBean(UserComponent.class);
//        bean.hello();
//        UserComponent bean = context.getBean("userComponent2",UserComponent.class);
//        bean.hello();
//        UserConfiguration bean = context.getBean(UserConfiguration.class);
//        bean.hello();
//        User user1= (User) context.getBean("u1");
//        User user2= (User) context.getBean("user2");
//        System.out.println(user1);
//        System.out.println(user2);
        UserController userController = (UserController) context.getBean("userController");
        userController.hello();
//        UserController3 userController3 = (UserController3) context.getBean("userController3");
//        userController3.hello();
//        UserController2 userController2 = (UserController2) context.getBean("userController2");
//        userController2.hello();
    }

}
